package se.webbzon.oschi01.worldeditor;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class WorldObjectInflatorGroup {
	
	// A hash map containing all inflators of this group
	private final Map<String,WorldObjectInflator> inflators;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new empty world object inflator group. **/
	public WorldObjectInflatorGroup() {
		this.inflators = new HashMap<String,WorldObjectInflator>();
	}
	
	/** Creates a new world object inflator group from a collection of
	 * world object inflators. **/
	public WorldObjectInflatorGroup(Collection<WorldObjectInflator> inflators) {
		this.inflators = new HashMap<String,WorldObjectInflator>();
		for (WorldObjectInflator inflator : inflators)
			this.inflators.put(inflator.getWorldObjectName(), inflator);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns true if the given inflator was added to the inflator group. 
	 * If an inflator already exists with the same world object name as 
	 * the added inflator then false is returned.**/
	public boolean addInflator(WorldObjectInflator inflator) {
		if (hasInflator(inflator))
			return false;
		else {
			inflators.put(inflator.getWorldObjectName(), inflator);
			return true;
		}
	}
	
	/** Returns true if the given inflator was removed from the inflator group. **/
	public boolean removeInflator(WorldObjectInflator inflator) {
		return inflators.remove(inflator.getWorldObjectName()) != null;
	}
	
	/** Returns true if the inflator group already has the given inflator. **/
	public boolean hasInflator(WorldObjectInflator inflator) {
		return inflators.get(inflator.getWorldObjectName()) == inflator;
	}
	
	/** Returns the world object inflator associated with the given 
	 * world object name. **/
	public WorldObjectInflator getInflator(String worldObjectName) {
		return inflators.get(worldObjectName);
	}

}
